<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('分配详情') }}</span>
    </div>

    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('基金名称')" prop="fundName">
        <el-input
          v-model="queryParams.fundName"
          :placeholder="$t('基金名称')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('分配批次')" prop="fpQc">
        <el-input
          v-model="queryParams.fpQc"
          :placeholder="$t('分配批次')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('分配时间')">
        <DatePicker
          v-model="dateRange"
          type="daterange"
        />

      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t("搜索") }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t("重置") }}</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="fundFpDetailsList" border>
      <el-table-column :label="$t('序号')" fixed="left" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('基金名称')" fixed="left" align="center" show-overflow-tooltip prop="fundName" width="200" />
      <el-table-column :label="$t('分配批次')" align="center" show-overflow-tooltip prop="fpQc" width="150" />
      <el-table-column :label="$t('分配时间')" align="center" show-overflow-tooltip prop="fpTime" width="110">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.fpTime) }}</span>
        </template>
      </el-table-column>

      <el-table-column :label="$t('分配总额') + $t('金额单位')" align="center" show-overflow-tooltip prop="totalAmount" min-width="160">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.totalAmount, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('分配币种')" align="center" show-overflow-tooltip prop="currency" width="110" />
      <!--      <el-table-column :label="$t('汇率')" align="center" show-overflow-tooltip prop="exchangeRate" width="110" />-->
      <!--      <el-table-column :label="$t('分配总额') + $t('RMB')" align="center" show-overflow-tooltip prop="totalAmountRmb" width="110" />-->

      <el-table-column :label="$t('本金及费用') + $t('金额单位')" align="center" show-overflow-tooltip prop="principalCost" min-width="160">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.principalCost, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('Hurdle') + $t('金额单位')" align="center" show-overflow-tooltip prop="hurdleTheory" min-width="160">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.hurdleTheory, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('追赶条款') + $t('金额单位')" min-width="160" align="center" show-overflow-tooltip prop="chaseTerms">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.chaseTerms, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('剩余分配') + $t('金额单位')" min-width="160" align="center" show-overflow-tooltip prop="surplusLp">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.surplusLp, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('税费') + $t('金额单位')" align="center" min-width="160" show-overflow-tooltip prop="taxeFee">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.taxeFee, 'w') }}</span>
        </template>
      </el-table-column>
      <!--<el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['fp:fp:remove']"
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="deleteHandle(scope.row)"
          >{{ $t('删除') }}</el-button>
        </template>
      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { delFundFpDetails, getDetailsBasedOnTheInvestorId } from '@/api/fund/fp/fundFpDetails'
export default {
  data() {
      return {
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // 基金分配-分配详情表格数据
          fundFpDetailsList: [],
          // 弹出层标题
          title: '',
          // 是否显示弹出层
          formOpen: false,
          // 查询参数
          queryParams: {
            fundName: '',
            fpQc: '',
            investorId: this.$route.query.lpId,
            pageNum: 1,
            pageSize: 10
          },
          // 日期范围
          dateRange: [],
          // 表单参数
          form: {},
          // 表单校验
          rules: {
          }
      }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询基金分配-分配详情列表 */
    getList() {
        this.loading = true
        getDetailsBasedOnTheInvestorId(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
            this.fundFpDetailsList = response.rows
            this.total = response.total
            this.loading = false
        })
    },

    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            fundId: this.$route.query.id,
            fpId: undefined,
            investorId: undefined,
            investorName: undefined,
            assignItems: undefined,
            fpTime: undefined,
            principalCost: undefined,
            priorityReturn: undefined,
            lpCapitalRatio: undefined,
            chaseTerms: undefined,
            surplusLp: undefined,
            taxeFee: undefined,
            allCapitalRatio: undefined,
            createBy: undefined,
            createTime: undefined,
            updateBy: undefined,
            updateTime: undefined,
            delFlag: undefined,
            remark: undefined
        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.dateRange = []
        this.queryParams.fundName = ''
        this.queryParams.fpQc = ''
        this.resetForm('queryForm')
        this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
        this.formOpen = true
        this.title = this.$t('分配详情')
        this.$nextTick(() => {
            this.$refs.fundFpDetailsForm.init(null)
        })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
        this.formOpen = true
        this.title = this.$t('分配详情')
        this.$nextTick(() => {
            // 调用form页面的 init 方法初始化数据
            this.$refs.fundFpDetailsForm.init(row)
        })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(function() {
            return delFundFpDetails(row.id)
        }).then(() => {
            this.getList()
            this.msgSuccess(this.$t('删除成功'))
        }).catch(function() {
        })
    }
  }
}
</script>
